package com.song.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.song.domain.Orders;
import com.song.domain.Product;
import com.song.entity.R;
import com.song.service.OrdersService;
import com.song.mapper.OrdersMapper;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【t_orders】的数据库操作Service实现
* @createDate 2024-06-15 10:37:20
*/
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders>
    implements OrdersService{

    private Product product ;

    @RabbitListener(queues = "orders")
    public void receive(Product product) {
        this.product = product;
    }

    @Override
    public R createOrders(Long id) {
        Orders orders =new Orders();
        orders.setPid(this.product.getId());
        System.err.println("得到商品ID");
         baseMapper.insert(orders);
         System.err.println("订单创建成功");
         //修改库存
         product.setAmount(product.getAmount()-1);
         //提交到数据库
         return R.ok();
    }
}




